import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * java对象之间的比较方式
 */
class Student implements Comparable<Student> {
    public String name;
    public  int age;
    public Student(String name,int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        Student student = (Student)obj;
        return this.name.equals(student.name);
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
class Cmp implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o2.age - o1.age;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Student student1 = new Student("zhangSan",17);
        Student student2 = new Student("zhangSan",35);
        PriorityQueue<Student> priorityQueue1 = new PriorityQueue<>();
        priorityQueue1.offer(student1);
        priorityQueue1.offer(student2);
        System.out.println(student1.compareTo(student2));

        PriorityQueue<Student> priorityQueue2 = new PriorityQueue<>(new Cmp());
        priorityQueue2.offer(student1);
        priorityQueue2.offer(student2);
        System.out.println(new Cmp().compare(student1, student2));
    }
    public static void main3(String[] args) {
        Student student1 = new Student("zhangSan",17);
        Student student2 = new Student("zhangSan",35);
        Cmp cmp = new Cmp();
        System.out.println(cmp.compare(student1, student2));
    }
    public static void main2(String[] args) {
        Student student1 = new Student("zhangSan",17);
        Student student2 = new Student("zhangSan",35);
        System.out.println(student1.compareTo(student2));
    }
    public static void main1(String[] args) {
        Student student1 = new Student("zhangSan",17);
        Student student2 = new Student("zhangSan",35);
        System.out.println(student1.equals(student2));
    }
}
